package com.sltx.controller;

import com.sltx.controller.base.BaseController;
import com.sltx.service.impl.SubjectReportServiceImpl;
import com.sltx.util.PageData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/subject")
public class SubjectReportController extends BaseController {

    @Autowired
    private SubjectReportServiceImpl service;

    /**
     * 获取纳税变动报告
     * @return
     */
    @RequestMapping("/getnsbd")
    @ResponseBody
    public Object getNsbdRport(){
        PageData pd = this.getPageData();
        List<Object> result = new ArrayList<>();

        Map map = new HashMap();
        map.put("qb", service.getHylbskje(pd));

        List<Map> allByTax = service.getAllByTax(pd);
        result.add(map);
        result.add(allByTax);
        return result;
    }

    /**
     * 获取政策兑现报告
     * @return
     */
    @RequestMapping("/getZcdx")
    @ResponseBody
    public Object getZcdxReport(){
        PageData pd = this.getPageData();
        return service.getZcdx(pd);
    }

    /**
     * 企业变更报告
     * @return
     */
    @RequestMapping("/getQybg")
    @ResponseBody
    public Object getQybgReport(){
        PageData pd = this.getPageData();
        List<Object> result = new ArrayList<>();
        Map qybg = service.getQybg(pd);
        List<Map> sw = service.getSw(pd);
        result.add(qybg);
        result.add(sw);

        List<Map> swqc = service.getSwqc(pd);
        List<Map> swqr = service.getSwqr(pd);
        result.add(swqc);
        result.add(swqr);

        return result;
    }

    /**
     * 生成报告
     * @return
     */
    @RequestMapping(value = "/generate", method = RequestMethod.GET)
    @ResponseBody
    public Object generateReport(HttpServletRequest request, String picBase64Info) throws IOException {
        logBefore(logger, "生成报告信息");
        PageData pd = this.getPageData();
        String type = pd.get("type").toString();
        String docName = "";
        String docPath = "";
        if (type != null && !type.equals("")) {
            if ("纳税变动报告".equals(type)) {
                docName = "纳税变动报告.doc";
            }
            if ("政策兑现报告".equals(type)) {//政策兑现报告
                docName = "政策兑现报告.doc";
            }
            if ("企业变更报告".equals(type)) {//企业变更报告
                docName = "企业变更报告.doc";
            }

            docPath = service.createDocContext(docName, picBase64Info, pd);//生成报告
        }
        String[] split = docPath.split(":");
        return split[split.length - 1];
    }

}